<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>flydesigner增加</title>
    <link rel="stylesheet" href="/static/component/layui/css/layui.css" />
    <link rel="stylesheet" href="/static/component/designer/modules/formDesigner.css" />
    <link rel="stylesheet" href="/static/component/designer/modules/cron.css" />
    <link rel="stylesheet" href="/static/component/designer/modules/labelGeneration.css" />
    <link rel="stylesheet" href="/static/component/designer/modules/formPreview.css" />
</head>

<body >
<div id="form" style="padding: 20px">

</div>
<script type="text/javascript" src="/static/component/layui/layui.js"></script>
<script type="text/javascript" src="/static/component/designer/modules/Sortable/Sortable.js"> </script>
<script type="text/javascript" src="/static/component/designer/modules/iceEditor/iceEditor.js"></script>

<script>
    var demojs = {$data|raw};

    layui.config(
        {base: '/static/component/designer/modules/'}).use(['formPreview', 'form', 'layer'], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var formPreview = layui.formPreview;
        var form = layui.form;
        var render;
        if (demojs) {
            render = formPreview.render({
                elem: '#form',
                data: demojs,
                //formData: {"textarea_1":"123","input_2":"123","password_3":"123"}
            });

        }
        // 监听提交

        form.on('submit(demo1)', function(data){
            let formData = render.getFormData()
            formData.id = {$id};
            formData.data_id = {$data_id};
            $.post('/flyDesigner/edit', formData, function (res) {
                // 判断有没有权限
                if (res && res.code == 999) {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 2000,
                    })
                    return false;
                } else if(res.code == 0) {
                    layer.msg(res.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.refresh();
                    });
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                }
            }, 'json');
            return false;
        });
    });
</script>
</body>

</html>